<template>
	<view class="myStore">
		<view v-if="true">
			<view class="st-header" style="background: url('/static/split-new/shopback.png') no-repeat ;background-size: 750upx 479upx;">
				<view class="hd-line2">
					<!-- @click="navTo('/pages/myStore/management/storeSelect')" -->
					我的资产
				</view>
				<view class="hd-line3">
					<view class="line3-item">
						<view class="item1 font24">
							可提现金
						</view>
						<view class="item2 font40" v-if="isLogin">
							{{money.cashMoney}}
						</view>
					</view>
					<view class="line3-item">
						<view class="item1 font24">
							不可用
						</view>
						<view class="item2 font40" v-if="isLogin">
							{{money.frozenMoney}}
						</view>
					</view>
				</view>
				<view class="hd-line4" @click="navTo('/pages/myStore/withdraw')">
					<text class="button1">提现</text>
				</view>
			</view>
			<view class="two-content">
				<view class="ct-item">
					<!-- <text class="button2" @click="relGoods">发布商品 <text class="iconfont" style="font-size: 24upx;">&#xe627;</text></text> -->
					<text class="button2" @click="navTo('/pages/myStore/goods/release')">发布商品</text>
					
				<!-- 	<view class="item-box" v-show="relFlag">
						<view @click="navTo('/pages/myStore/goods/release')" v-show="user_type == 3">
							商户
						</view>
						<view class="hr" v-show="user_type == 3">
						</view>
						<view @click="navTo('/pages/myStore/goods/release-ttc')" v-show="user_type == 3">
							土特产
						</view>
						<view class="hr" v-show="user_type == 3">
						</view>
						<view @click="navTo('/pages/myStore/goods/release-ershou')">
							二手
						</view>
					</view> -->
					
				</view>
				<view class="ct-item">
					<text class="button2" @click="navTo('/pages/order/lph-order')">销售订单</text>
				</view>
				<view class="ct-item">
					<text class="button2" @click="navTo('/pages/myStore/history-bill')">历史订单</text>
				</view>
			</view>
			
			<view class="user-order">
				<view class="od-title" >
					<text class="text1">{{shopName}}</text>
					<text class="text2" @click="navTo('/pages/myStore/setting/shopDetils')">设置<text class="iconfont" style="font-size: 24upx;">&#xe600;</text></text>
				</view>
				<view class="od-content">
				<!-- 	<view class="od-item" @click="navTo('/pages/myStore/goods/goods')">
						<image src="/static/imgs/myStore/myStoreIcon-01.png" mode=""></image>
						<view>
							商品管理
						</view>
					</view> -->
					<view class="od-item" @click="navTo('/pages/myStore/shop/shop')">
						<image src="/static/imgs/myStore/myStoreIcon-02.png" mode=""></image>
						<view>
							店铺管理
						</view>
					</view>
					<view class="od-item" @click="navTo('/pages/myStore/discount/discount')">
						<image src="/static/imgs/myStore/myStoreIcon-03.png" mode=""></image>
						<view>
							满减
						</view>
					</view>
					<view class="od-item" @click="navTo('/pages/myStore/bill/bill')">
						<image src="/static/imgs/myStore/myStoreIcon-04.png" mode=""></image>
						<view>
							账单管理
						</view>
					</view>
					<view class="od-item" @click="navTo('/pages/myStore/refund/refund')">
						<image src="/static/imgs/myStore/myStoreIcon-08.png" mode=""></image>
						<view>
							退款管理
						</view>
					</view>
					<view class="od-item" @click="navTo('/pages/myStore/complaint/complaint')">
						<image src="../../static/imgs/myStore/myStoreIcon-05.png" mode=""></image>
						<view>
							投诉管理
						</view>
					</view>
					<view class="od-item" @click="navTo('/pages/myStore/leaveComments/assess')">
						<image src="/static/imgs/myStore/myStoreIcon-06.png" mode=""></image>
						<view>
							评价管理
						</view>
					</view>
					<view class="od-item" @click="navTo('/pages/myStore/leaveComments/leaveComments')">
						<image src="/static/imgs/myStore/myStoreIcon-07.png" mode=""></image>
						<view>
							留言管理
						</view>
					</view>
				
			
				</view>
			</view>
			
		</view>
		<!-- 石 -->
		<!-- 未开通我的店 -->
		<view>
			<sDialog class="mode-dialog" v-model="visible" :maskClose="false">
				<view class="tipsImg" style="background-image: url(/static/imgs/myStore/pic_01.png);">
					<view class="tipsContent">
						<text>您还没开通我的店</text>
						<text>请您通过实名认证，开通我的店</text>
						<view class="">
							<button type="default" style="color: #999999;" @click="switchTab('/pages/user/user')">知道了</button>
							<button type="primary" @click="navTo('/pages/myStore/management/storeSelect')">立即开通</button>
						</view>
					</view>
				</view>
			</sDialog>
		</view>
		
		<!-- 未登录进入我的店提示 -->
		<view>
			<sDialog class="mode-dialog" v-model="loginVisible" :maskClose="false">
				<view class="tipsImg" style="background-image: url(/static/imgs/myStore/pic_01.png);">
					<view class="tipsContent">
						<text>您还没有登录！</text>
						<text>登录后可进入我的店！</text>
						<view class="">
							<button type="default" style="color: #999999;" @click="switchTab('/pages/index/index')">去逛逛</button>
							<button type="primary" @click="navTo('/pages/public/userLogin')">立即登录</button>
						</view>
					</view>
				</view>
			</sDialog>
		</view>
		
		<QSPopup ref="QSPopupRz1" type="fadeInMiddleRz" :tapMaskHide="false">
			<!-- 1 -->
			<view class="rz qs-popup" v-if="rzFlag == 0">
				<image src="/static/imgs/myStore/certification.png" mode="aspectFill"></image>
				<view class="title">
					资料正在审核中！
				</view>
				<view class="hint">
					您已提交成功，请耐心等候1-2个工作日，谢谢！
				</view>
				<button class="button1" @click="switchTab('/pages/user/user')">返回个人中心</button>
			</view>
			<!-- 2 -->
			<view class="rz qs-popup" v-if="rzFlag == 1">
				<image src="/static/imgs/myStore/certificationSuccess.png" mode="aspectFill"></image>
				<view class="title">
					恭喜您，认证成功
				</view>
				<view class="hint">
					赶快去上架宝贝管理店铺吧！
				</view>
				<button class="button1 wdd" @click="switchTab1('/pages/myStore/myStore')">去我的店</button>
			</view>
			<!-- 3 -->
			<view class="rz qs-popup" v-if="rzFlag == 2">
				<image src="/static/imgs/myStore/certification.png" mode="aspectFill"></image>
				<view class="title">
					很抱歉，认证失败！
				</view>
				<view class="hint">
					{{rzDes}}
				</view>
				<button class="button1 anew" @click="navTo('/pages/myStore/management/storeSelect')">重新认证</button>
			</view>
		</QSPopup>
		
		<!-- 蒙版 -->
		<view class="mask" v-show="relFlag" @click="onMask" @touchmove="onMask">
		</view>
		
	</view>
</template>

<script>
	import { mapState } from 'vuex';
	import sDialog from '@/components/s-dialog/index.vue';
	import QSPopup from '@/components/QS-popup/QS-popup.vue';
	export default {
		components:{
			sDialog,
			QSPopup
		},
		data() {
			return {
				loginVisible:false,
				visible:false, // 开通我的店 弹窗
				money: { // 资产情况
					cashMoney: 0,
					frozenMoney: 0
				}, 
				relFlag: false, // 发布商品的显示
				user_type: '', // 用户类型
				rzFlag: -1, // 认证状态
				shopName: '', // 店铺名
				rzDes: '', // 店铺认证失败，返回的信息
				isLogin: false, // 是否登录
			};
		},
		onLoad() {
			let token = uni.getStorageSync('lph-token');
			if(token){
				// #ifdef APP-PLUS
				this.getLL();
				// #endif	
			}
			/*  */
		},
		onShow() {
			let token = uni.getStorageSync('lph-token');
			// this.visible = false;
			if(token){
				this.visible = true;
				this.isLogin = true;
				this.judgeShop();
			}else{
				this.loginVisible = true
			}
			
		},
		onPullDownRefresh() { // 下拉刷新的处理
			let token = uni.getStorageSync('lph-token');
			if(token){
				this.get_money();
			}
			
		},
		computed: {
			...mapState(['userInfo'])
		},
		methods: {
			async judgeShop() { // 判断是否开通了我的店
				let a = uni.getStorageSync('lph-user-info');
				a.user_type == 1 ? this.visible = true : this.visible = false ;// 判断是否开通了我的店
				this.user_type = a.user_type;
				if(this.user_type != 1) {
					let b =	await this.$http.getMyShop();
					this.shopName = b.data.shname;
					// 0待审核 1 审核通过 2 未通过
					switch (b.data.isauth){
						case 0:
						this.rzFlag = 0;
						this.$refs['QSPopupRz1'].show();
							break;
						case 1:
							this.get_money();
							if(b.data.is_display == 1) {
								this.rzFlag = 1;
								this.$refs['QSPopupRz1'].show();
								return
							}
							break;
						case 2:
						this.rzFlag = 2;
						this.rzDes = b.data.reject_comment;
						this.$refs['QSPopupRz1'].show();
							break;
						default:
							break;
					}
				}
			},
			show(ref){
				this.$refs[ref].show();
			},
			hide(ref){
				this.$refs[ref].hide();
			},
			getLL() { // 获取经纬度，并保持到缓存中
				uni.getLocation({
				    type: 'wgs84',
				    success: function (res) {
								uni.setStorageSync("lph-ll",{long: res.longitude,lat: res.latitude})
				    }
				});
			},
			//设置
			navTo(url){
				this.relFlag = false;
				this.loginVisible = false
				uni.navigateTo({url});
			},
			async get_money() {
				let money = await this.$http.getMoney();
				this.money = money.data;
				uni.stopPullDownRefresh();
			},
			onMask() { // 触摸蒙版后的处理
				this.relFlag = !this.relFlag;
			},
			relGoods() { // 点击发布商品
				this.relFlag = !this.relFlag;
			},
			switchTab(url) {
				uni.switchTab({url})
			},
			async	switchTab1(url) {
				this.$refs['QSPopupRz1'].hide();
				await this.$http.setIsDisplay();
				uni.switchTab({url})
			},
		}
	}
</script>

<style lang="scss" scoped>
	@import 'static/css/myStore.scss';
	@import 'static/css/smallCommon.scss';
</style>
